import scrapy


class QuotesSpider(scrapy.Spider):
    name = "link"
    start_urls = [
        'https://tieba.baidu.com/f?kw=%E9%9B%B7%E5%87%8C&ie=utf-8&pn=0',
    ]

    def parse(self, response):
        for quote in response.css('div.quote'):
            yield {
                'text': quote.css('span.text::text').extract_first(),
                'author': quote.css('span small::text').extract_first(),
                'tags': quote.css('div.tags a.tag::text').extract(),
            }

        next_page = response.css('a.next.pagination-item::attr(href)').extract_first()
        # next_page = response.xpath('/html/body/div/div[2]/div[1]/nav/ul/li/a/@href').extract()
        # response.xpath("/html/body/div/div[2]/div[1]/nav/ul/li[2]/a")
        print(next_page)
        if next_page is not None:
            yield response.follow(next_page, callback=self.parse)
